package com.itheima.controller;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.entity.Setmeal;
import com.itheima.service.SetMealService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * @className SetMealController
 */
@RestController
@RequestMapping("/setmeal")
@RequiredArgsConstructor
public class SetMealController {

    private final SetMealService setMealService;

    /**
     * 获取套餐列表
     * @return
     */
    @PostMapping("/getSetmeal")
    public Result getSetMealList(){
        List<Setmeal> setMealList = setMealService.getSetMealList();
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,setMealList);
    }

    /**
     * 根据套餐id查询套餐详情
     * @param id 套餐id
     * @return
     */
    @PostMapping("/findById")
    public Result getSetMealById(Integer id){
        Setmeal setMeal = setMealService.getSetMealById(id);
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,setMeal);
    }
}
